
# 获取用户列表
from rest_framework.generics import ListAPIView, CreateAPIView

from meiduo_admin.admin_user.user_serializer import UserListSerializer
from meiduo_admin.my_paginate import MyPageNumberPagination
from user.models import User


class UserListView(ListAPIView,CreateAPIView):
    queryset = User.objects.all()
    serializer_class = UserListSerializer
    pagination_class = MyPageNumberPagination

    def get_queryset(self):
        keyword=self.request.query_params.get('keyword')
        if keyword:
            return User.objects.filter(username__contains=keyword).all()
        else:
            return User.objects.all()
